﻿function toggleMenu(title) {
    $(".managelist:not(#" + title + ")").hide("slow");
    $("#" + title).show("slow");
}

$(function () {
    $(".listtable tr:even").addClass("ji");
    $(".listtable tr:odd").addClass("odd");
    $(".listtable tr").mouseover(function () {
        $(this).addClass("over");
    });
    $(".listtable tr").mouseout(function () {
        $(this).removeClass("over");
    });
});


$(function () {
    $(".catName").click(function tdclick() {
        var tdobj = $(this);
        if (tdobj.children("input").length == 0) {
            oldvalue = $.trim(tdobj.text());
        }
        else {
            return;
        }
        //if (oldvalue == undefined || oldvalue == "" || oldvalue == null) {
        //    return;
        //}
        var inputobj = $("<input type=text value='" + oldvalue + "' />");
        tdobj.html(inputobj);
        inputobj.trigger("focus").trigger("select");
        tdobj.unbind("click", tdclick);
        inputobj.blur(function () {
            var newvalue = $.trim(inputobj.val());
            if (newvalue != oldvalue) {
                var catid = $.trim(tdobj.attr("catid"));
                var geturl = "../CatMgr/UpdateCat.ashx?catid=" + catid + "&newname=" + encodeURI(encodeURI(newvalue)) + "&paras=" + new Date().getTime();
                $.get(geturl, function (data) {
                    if (data == "Has") {
                        alert("栏目名称已经存在");
                        tdobj.html(oldvalue);
                    }
                    else if (data == "Error") {
                        alert("添加失败，请查找原因");
                        tdobj.html(oldvalue);
                    }
                    else {
                        tdobj.html(newvalue);
                    }
                });
            }
            else {
                tdobj.html(oldvalue);
            }
            tdobj.bind("click", tdclick);
        });

        //inputobj.onkeydown(function (event) {
        //    alert(event.keyCode);
        //    if (event.keyCode != 13)
        //    {
        //        return false;
        //    }
        //    if (newvalue != oldvalue) {
        //        var catid = $.trim(tdobj.attr("catid"));
        //        var geturl = "../../Handler/UpdateCat.ashx?catid=" + catid + "&newname=" + encodeURI(encodeURI(newvalue)) + "&paras=" + new Date().getTime();
        //        $.get(geturl, function (data) {
        //            alert(data);
        //            if (data == "Has") {
        //                //alert("栏目名称已经存在");
        //                tdobj.html(oldvalue);
        //            }
        //            else if (data == "Error") {
        //                alert("添加失败，请查找原因");
        //                tdobj.html(oldvalue);
        //            }
        //            else {
        //                tdobj.html(newvalue);
        //            }
        //        });
        //    }
        //});


    });
});


//屏蔽全文回车键
//$(document).keydown(function (event) {
//    switch (event.keyCode) {
//        case 13:  return false;
//    }
//});

//$(window).keydown(function (event) {
//    switch (event.keyCode)
//    {
//        case 13: return false;
//    }
//});

document.onkeydown = function (event) {

    //var er = event.srcElement;
    if (navigator.userAgent.indexOf("MSIE") <= 0) {
        event = SearchEvent();
    }
    if (event.keyCode == 13) {
        event.returnValue = false; // 这是完全屏蔽

        //var button = document.getElementByIdx_x("<%=lb_UpdateAmount.ClientID%>");
        //button.click(); 
        //__doPostBack("<%=lb_UpdateAmount.UniqueID%>",'')                
        return false;

    }
}


//如果浏览器为FireFox，在使用event变量前，则需先调用自定义的SearchEvent()函数，该函数代码如下：
function SearchEvent() {
    if (document.all)
        return window.event;
    func = SearchEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0) {
            if (arg0.constructor == Event || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation))
                return arg0;
        }
        func = func.caller;
    }
    return null;
}

